<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
<h2>
    <?= esc($title) ?>
    <a href="/news/new" title="Add News">
        <i class="bi bi-plus-circle"></i>
    </a>
</h2>

<?php if ($news_list !== []): ?>
    <!-- 修改：添加折叠样式 -->
    <div class="accordion" id="newsAccordion">
        <?php foreach ($news_list as $index => $news_item): ?>
            <div class="accordion-item">
                <h2 class="accordion-header">
                    <button class="accordion-button <?= $index > 0 ? 'collapsed' : '' ?>" 
                            type="button" 
                            data-bs-toggle="collapse" 
                            data-bs-target="#collapse<?= $index ?>" 
                            aria-expanded="<?= $index === 0 ? 'true' : 'false' ?>" 
                            aria-controls="collapse<?= $index ?>">
                        <?= esc($news_item['title']) ?>
                    </button>
                </h2>
                <div id="collapse<?= $index ?>" 
                     class="accordion-collapse collapse <?= $index === 0 ? 'show' : '' ?>" 
                     data-bs-parent="#newsAccordion">
                    <div class="accordion-body">
                        <div class="main mb-3">
                            <?= esc($news_item['body']) ?>
                        </div>
                        
                        <div class="btn-group" role="group">
                            <!-- 查看 -->
                            <a href="/news/<?= esc($news_item['slug'], 'url') ?>" 
                               
                               title="View">
                                <i class="bi bi-eye"></i>
                            </a>

                            <!-- 删除-->
                            <a href="/news/delete/<?= $news_item['id'] ?>" 
                                
                               title="Delete"
                               onclick="return confirm('Are you sure you want to delete this news item?')">
                                <i class="bi bi-trash"></i>
                            </a>
                        </div>
                    </div>
                </div>
            </div>
        <?php endforeach ?>
    </div>
<?php else: ?>

    <h3>No News</h3>

    <p>Unable to find any news for you.</p>

<?php endif ?>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/js/bootstrap.bundle.min.js"></script>